package com.adxon.servlet;

import com.adxon.MsgException;
import com.adxon.Uri;
import com.adxon.data.Figure;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class ImageServlet extends ServletBase{
	public void doGet(HttpServletRequest req,HttpServletResponse resp)
			throws IOException,ServletException{
		/*try{
			String p=req.getPathInfo();
			System.out.println("ImageServlet: "+p);
			if(p==null||p.length()==1){
				PreparedQuery r=Figure.query(20);
				StringBuilder b=new StringBuilder();
				for(Entity t:r.asIterable()){
					Figure o=new Figure();
						o.update(t);
					String n=o.getPermaLink();
					b.append("<a href=/image/");
					b.append(n);
					b.append("><img src=/image/");
					b.append(n);
					b.append(".t.jpg></a>");
				}
				setAttributes(req,"Images");
				req.setAttribute("Article",b.toString());
			}else{
				Uri i=new Uri(p);
				p=i.getId();
				if(i.getExtension()==null){
					setAttributes(req,p);
					req.setAttribute("Article","<img src=/image/"+p+'.'+"jpg>");
					req.setAttribute("Aside","<ul><li><a href=/sys/upload>Upload</a><li><a href=/image/>Images</a></ul>");
				}else{
					Figure o=new Figure();
					o.setPermaLink(p);
					o.update();
					cacheControl(resp,360000);
					resp.setContentType(o.getContentType());
					resp.getOutputStream().write(o.getBits(i.getType()));
					o.commit();		// update extra blobs
					/*
					byte[] b=o.getBits("t");
					int n=0;
					for(int x:b){
						String c=Integer.toString(x);
						int d=c.length()+1;
						n+=d;
						if(n>67){
							System.out.println();
							n=d;
						}
						System.out.print(c+',');
					}
					return;
				}
			}
			forward("article.jsp",req,resp);
		}catch(MsgException e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			e.routing(req,resp);
		}*/
	}
}